/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.SerialFieldTag;

/**
 * Implementation of {@link SerialFieldTag}
 *
 * @author Chad Retz
 */
@XmlType(name = "serialFieldTag")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public class SerialFieldTagImpl extends TagImpl implements SerialFieldTag {

    //exposed fields
    
    @Expose
    private String description;
    
    @Expose
    private String fieldName;
    
    @Expose
    private String fieldType;
    
    @Expose
    private String fieldTypeDoc;
    
    //non-exposed fields
    
    private transient ClassDocImpl fieldTypeDocLoaded;
    
    //SerialFieldTag interface impl
    
    @Override
    public int compareTo(Object obj) {
        if (obj instanceof SerialFieldTagImpl) {
            //TODO: doesn't seem right...
            return fieldName.compareTo(((SerialFieldTagImpl) obj).fieldName);
        }
        return -1;
    }
    
    @Override
    public String description() {
        return description;
    }
    
    @Override
    public String fieldName() {
        return fieldName;
    }
    
    @Override
    public String fieldType() {
        return fieldType;
    }
    
    @Override
    public ClassDocImpl fieldTypeDoc() {
        if (fieldTypeDocLoaded == null) {
            fieldTypeDocLoaded = getContext().getClassDoc(fieldTypeDoc);
        }
        return fieldTypeDocLoaded;
    }
    
    //other accessors
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }
    
    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }
    
    public String getFieldTypeDoc() {
        return fieldTypeDoc;
    }
    
    public void setFieldTypeDoc(String fieldTypeDoc) {
        this.fieldTypeDoc = fieldTypeDoc;
    }
}
